package com.agency8x.validator;

import com.agency8x.config.AppConf;
import com.agency8x.model.LoginModel;
import com.agency8x.model.WithdrawModel;
import com.agency8x.web.util.ValidatorUtil;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.validate.Validator;

/**
 * WithdrawValidator.
 */
public class WithdrawValidator extends Validator {

	protected void validate(Controller controller) {
		validateRequiredString("status", "statusMsg", "审核结果无效!");
		validateRequiredString("id", "idMsg", "编号无效!");
		Integer status = controller.getParaToInt("status", 0);
		String remark = controller.getPara("rejected_remark");
		if (status < 1 && StrKit.isBlank(remark)) {
			this.addError("remarkMsg", "请在审核备注中填写驳回原因!");
		}
		LoginModel loginBean = LoginModel.getLoginInfo(controller, AppConf.loginSessionID);
		if (null == loginBean) {
			this.addError("loginMsg", "未登录或登录超时!");
		}
	}

	protected void handleError(Controller controller) {
		ValidatorUtil.errorJson(controller, new String[] { "statusMsg", "idMsg", "remarkMsg", "loginMsg" });
	}
}
